wfopen  "C:\Users\Maryam\Desktop\BS Studies\PhD Thesis-II\EViews and STATA Progarm Codes\Chapter-8\Hong Kong.wf1"
'******************************************************************
'Group Plots for Real Exchange Rate (NT) & Productivity Gap
'******************************************************************
group gA rer_def_NT_4 A_tilde_4
freeze(group_plot) gA.line(x)
group_plot.setelem(1) lcolor(black) symbol(7) lpat(1)
group_plot.setelem(2) lcolor(black) symbol(4) lpat(1)
group_plot.setelem(3) lcolor(black) symbol(1) lpat(1)
group_plot.setelem(3) lcolor(black)
group_plot.options linepat
group_plot.addtext(t) Real Exchange Rate (NT-based) and Productivity Gaps (Hong Kong & U.S): 1980-2008
group_plot.addtext(b) Year
group_plot.addtext(l) PNT  
group_plot.addtext(l) NER 
group_plot.addtext(l) rer_def_NT_4
group_plot.addtext(r) A_TILDE_4
'************************************************************
'************************************************************

create y 1980 2008
'importing data from Excel for Hong Kong
import  "C:\Users\Maryam\Desktop\BS Studies\PhD Thesis-II\EViews and STATA Progarm Codes\Chapter-8\Chapter 8.xlsx" range="Hong Kong"

'**************************************************************************************************
'VERIFYING THE ASSUMPTION OF PPP FOR Hong Kong AND U.S. TRADABLES PRICES
'**************************************************************************************************
'*************************************************************
'STEP 0: Tests for Unit Root in Individual Time Series
'*************************************************************

'***************************************************************
'Graph for Hong Kong's  pT_4
'***************************************************************
                                        
genr pT_4 = pT_4
freeze(figure_pT_4) pT_4.line
figure_pT_4.addtext(t) pT_4 (Hong Kong):  1980-2008
figure_pT_4.addtext(b) Year
figure_pT_4.addtext(l) pT_4
figure_pT_4.legend(off)
                                                 
'We see from the FIGURE that pT_4 has a time trend to it.  So we would include both an intercept and a time trend in our unit root regression equtions. 

'*********************************************************************************
'ADF Unit Root Test for Hong Kong's pT_4
'We now run our first ADF test
'**********************************************************************************
 
freeze(table_8_1_1_pT_4_adf) pT_4.uroot(adf,trend,lag=1)

'Note that I specify lags, p = 1 for obtaining white noise residuals. The unit root test produces a t-value of -0.69 which is greater than our 5% criterion -3.59.  Thus, at this point, we cannot reject the null of a unit root.

'Now, let's check for white noise.  To do that, I first set all the residuals = 0, then run the adf test and finally will check for white noise.

genr resid = 0
freeze(mode=overwrite,pT_4_adf) pT_4.uroot(adf,const,trend,lag=1)
freeze(pT_4_adf_correl) resid.correl
 
'Based on the Q-statistic, I conclude that the residuals are white noise.  Putting it all together, I conclude that the pT_4 series is not level stationary.

'The next thing I do is test whether the differenced series is stationary using the ADF test.  I once again begin by graphing the (differenced) series.
 
genr pT_4diff = d(pT_4)
freeze(figure_pT_4diff) pT_4diff.line
figure_pT_4diff.addtext(t) DpT_4 (Hong Kong):  1980-2008
figure_pT_4diff.addtext(b) Year
figure_pT_4diff.addtext(l) DpT_4
figure_pT_4diff.legend(off)

'The graph is not particularly illuminating.  Depending on how you look at it, it could have a time trend to it.  However, since the previous ADF test concluded that the equation for pT_4 do have a time trend, we run the ADF test with both a constant as well as a time trend.

'So we begin the whole process over again: 

genr pT_4diff = d(pT_4)
freeze(table_8_1_2_pT_4diff1_adf) pT_4diff.uroot(adf,const,lag=1)

'Note that I specify lags, p =1, for obtaining white noise residuals. The unit root test produces a t-value of -1.35 which is still greater our 5% criterion -2.98.  Thus, we may not reject the null of nonstationarity in first differenced series of pT_4.  There is no reason to go further.  The last thing we do is check for white noise.

genr resid = 0
freeze(mode=overwrite,pT_4diff1_adf) pT_4diff.uroot(adf,const,trend,lag=1)
freeze(pT_4diff1_adf_correl) resid.correl

''Based on the Q-statistic, I conclude that the residuals are white noise.  Putting it all together, I conclude that the pT_4 series is greater than I(1).

'*********************************************************************************
'DF-GLS Unit Root Test for Hong Kong's pT_4
'We now run our first dfgls test
'**********************************************************************************
 
freeze(table_8_1_3_pT_4_dfgls) pT_4.uroot(dfgls,trend,lag=1)

'Note that I specify lags, p =1, for obtaining white noise residuals. The unit root test produces a t-value of -1.11 which is greater than our 5% criterion -3.19.  Thus, at this point, we may not reject the null of a unit root.

'Now let's see if the series is difference stationary or not

genr pT_4diff = d(pT_4)
freeze(table_8_1_4_pT_4diff1_dfgls) pT_4diff.uroot(dfgls,const,lag=1)

'Note that I specify lags, p =1, for obtaining white noise residuals. The unit root test produces a t-value of -1.19 which is greater than our 5% criterion -1.95.  Thus, we may not reject the null of nonstationarity in first differenced series of pT_4.  
 
''Putting it all together, I conclude that the pT_4 series is greater than I(1), a finding compatable with my ADF test results.

'***************************************************************
'Graph for Hong Kong's  pT_us_PPP
'***************************************************************
                                        
genr pT_us_PPP = pT_us_PPP
freeze(figure_pT_us_PPP) pT_us_PPP.line
figure_pT_us_PPP.addtext(t) pT_us_PPP (Hong Kong):  1980-2008
figure_pT_us_PPP.addtext(b) Year
figure_pT_us_PPP.addtext(l) pT_us_PPP
figure_pT_us_PPP.legend(off)
                                                 
'We see from the FIGURE that pT_us_PPP has a time trend to it.  So we would include both an intercepT_us_PPP and a time trend in our unit root regression equtions. 

'*********************************************************************************
'ADF Unit Root Test for Hong Kong's pT_us_PPP
'We now run our first ADF test
'**********************************************************************************
 
freeze(table_8_1_1_pT_us_PPP_adf) pT_us_PPP.uroot(adf,trend,info=sic)

'Note that the SIC automatic lag selection picks lags, p = 1.  The unit root test produces a t-value of -3.62 which is smaller than our 5% criterion -3.59.  Thus, at this point, we can reject the null of a unit root.

'Now, let's check for white noise.  To do that, I first set all the residuals = 0, then run the adf test and finally will check for white noise.

genr resid = 0
freeze(mode=overwrite,pT_us_PPP_adf) pT_us_PPP.uroot(adf,const,trend,info=sic)
freeze(pT_us_PPP_adf_correl) resid.correl
 
'Based on the Q-statistic, I conclude that the residuals are white noise.  Putting it all together, I conclude that the pT_us_PPP series is level stationary.

'*********************************************************************************
'DF-GLS Unit Root Test for Hong Kong's pT_us_PPP
'We now run our first dfgls test
'**********************************************************************************
 
freeze(table_8_1_3_pT_us_PPP_dfgls) pT_us_PPP.uroot(dfgls,trend,info=sic)

'Note that the SIC automatic lag selection picks lags, p = 1.  The unit root test produces a t-value of -1.816 which is greater than our 5% criterion -3.19.  Thus, at this point, we may not reject the null of a unit root.

'Now let's see if the series is difference stationary or not

genr pT_us_PPPdiff = d(pT_us_PPP)
freeze(table_8_1_4_pT_us_PPPdiff1_dfgls) pT_us_PPPdiff.uroot(dfgls,const,info=sic)

'Note that the SIC automatic lag selection picks no lags, p = 0.  The unit root test produces a t-value of -2.13 which is smaller than our 5% criterion -1.95.  Thus, we may now reject the null of nonstationarity in first differenced series of pT_us_PPP.  
 
''Putting it all together, I conclude that the pT_us_PPP series is I(1), a finding incompatable with my ADF test results.

''******************************************************************************************
''S1: Establishing Cointegration for Verifying PPP for Inter-Country Tradables Prices
'******************************************************************************************
'Now, by employing FMOLS and DOLS cointegration regression estimators, we shall calculate our LR cointegrating vectors.

equation table_8_1_LRPPP_fmols.cointreg(method=fmols) pT_4 pT_us_PPP

equation table_8_1_LRPPP_dols.cointreg(method=dols, trend=constant, lag=1,lead=1 ) pT_4 pT_us_PPP

'As proven by FMOLS and DOLS test results, valid cointegration holds between pT_4 and pT_us_PPP. Thus, I can proceed with estimation of S2 condition. 

''************************************************************************************************
''S2: Testing for Equi-proportionate Relationship between Inter-Country Tradables Prices
'************************************************************************************************

freeze(table_8_1_LRPPP_fmols_Ftest) table_8_1_LRPPP_fmols.wald c(1)=1

freeze(table_8_1_LRPPP_dols_Ftest) table_8_1_LRPPP_dols.wald c(1)=1


'As proven by both Wald coefficient test results for FMOLS and DOLS estimates, PPP does not validly hold for traded sector prices of Hong Kong and U.S. Thus, I will proceed with estimating the modified version of BS hypothesis. 

'***************************************************************************************
'ESTIMATING BALASSA-SAMUELSON EFFECT FOR rer_def_NT_4, rer_def_T_4  & a_tilde_4
'**************************************************************************************
'*************************************************************
'STEP 0: Tests for Unit Root in Individual Time Series
'*************************************************************
'***************************************************************
'Graph for Hong Kong's  rer_def_NT_4
'***************************************************************
                                        
genr rer_def_NT_4 = rer_def_NT_4
freeze(figure_rer_def_NT_4) rer_def_NT_4.line
figure_rer_def_NT_4.addtext(t) rer_def_NT_4 (Hong Kong):  1980-2013
figure_rer_def_NT_4.addtext(b) Year
figure_rer_def_NT_4.addtext(l) rer_def_NT_4
figure_rer_def_NT_4.legend(off)
                                                 
'We see from the FIGURE that rer_def_NT_4 has a time trend to it.  So we would include both an intercept and a time trend in our unit root regression equtions. 

'******************************************************
'ADF Unit Root Test for Hong Kong's rer_def_nt_4
'******************************************************
 
freeze(table_8_14_rer_def_nt_4_adf) rer_def_nt_4.uroot(adf,trend,lag=2)

'Note that I had to specify lags, p = 2 to obtain white residuals from unit root test regression. The unit root test produces a t-value of -2.48 which is greater than our 5% criterion -3.59.  Thus, at this point, we cannot reject the null of a unit root.

'Now, let's check for white noise. To do that, I first set all the residuals = 0, then run the ADF test and finally will check for white noise.

genr resid = 0
freeze(mode=overwrite,rer_def_nt_4_adf) rer_def_nt_4.uroot(adf,const,trend,lag=2)
freeze(rer_def_nt_4_adf_correl) resid.correl
 
'Based on the Q-statistic, I conclude that the residuals are white noise.  Putting it all together, I conclude that the rer_def_nt_4 series is not level stationary.

'The next thing I do is test whether the differenced series is stationary using the ADF test.  I once again begin by graphing the (differenced) series.
 
genr rer_def_nt_4diff = d(rer_def_nt_4)
freeze(figure_rer_def_nt_4diff) rer_def_nt_4diff.line
figure_rer_def_nt_4diff.addtext(t) drer_def_nt_4 (Hong Kong):  1980-2008
figure_rer_def_nt_4diff.addtext(b) Year
figure_rer_def_nt_4diff.addtext(l) drer_def_nt_4
figure_rer_def_nt_4diff.legend(off)

'From the graph, the series clearly does not have a time trend to it. So, I would test the series for unit with an intercept only.

'So we begin the whole process over again: 

genr rer_def_nt_4diff = d(rer_def_nt_4)
freeze(table_8_14_rer_def_nt_4diff1_adf) rer_def_nt_4diff.uroot(adf,const,info=sic)

'Note that the SIC automatic lag selection picks no lags, p =0.  The unit root test produces a t-value of -2.50 which is still greater than our 5% criterion -2.97.  Thus, we may not reject the null of non-stationarity in first differenced series of rer_def_nt_4.  There is no reason to go further.  The last thing we do is to check ADF regression result for white noise.

genr resid = 0
freeze(mode=overwrite,rer_def_nt_4diff1_adf) rer_def_nt_4diff.uroot(adf,const,info=sic)
freeze(rer_def_nt_4diff1_adf_correl) resid.correl

''Based on the Q-statistic, I conclude that the residuals are white noise. Putting it all together, I conclude that the rer_def_nt_4 series is greater than I(1).

'**************************************************************
'DF-GLS Unit Root Test for Hong Kong's rer_def_nt_4
'**************************************************************
 
freeze(table_8_14a_rer_def_nt_4_dfgls) rer_def_nt_4.uroot(dfgls,trend,lag=2)

'Note that I had to specify lags, p = 2 to obtain white residuals from unit root test regression. The unit root test produces a t-value of -2.86 which is greater than our 5% criterion -3.19. Thus, at this point, we may not reject the null of a unit root. 

'Now let's see if the series is difference stationary or not

Genr rer_def_nt_4diff = d(rer_def_nt_4)
freeze(table_8_14b_rer_def_nt_41diff1_dfgls) rer_def_nt_4diff.uroot(dfgls,const,info=sic)

'Note that the SIC automatic lag selection picks no lags, p = 0.  The unit root test produces a t-value of -2.42 which is now smaller than our 5% criterion -1.95. Thus, we may reject the null of non-stationarity in first differenced series of rer_def_nt_4.  

''Putting it all together, I conclude that the rer_def_nt_4 series is I(1), a finding incompatible with my ADF test results.
'*************************************************
'Graph for Hong Kong's Productivity (a_tilde_4)
'*************************************************
                                        
genr a_tilde_4 = a_tilde_4
freeze(figurea_tilde_4) a_tilde_4.line
figurea_tilde_4.addtext(t) a_tilde_4 (Hong Kong):  1980-2008
figurea_tilde_4.addtext(b) Year
figurea_tilde_4.addtext(l) a_tilde_4
figurea_tilde_4.legend(off)
                                                 
'We see from the FIGURE that a_tilde_4 has time trend to it.  So we would include both an intercept and a time trend in our unit root regression equations. 

'*******************************************************
'ADF Unit Root Test for Hong Kong's Productivity
'*******************************************************
 
freeze(table_8_14_a_tilde_4_adf) a_tilde_4.uroot(adf,trend,info=sic)

'Note that the SIC automatic lag selection picks lags, p =1.  The unit root test produces a t-value of -1.19 which is greater than our 5% criterion -3.59.  Thus, at this point, we cannot reject the null of a unit root.

'Now, let's check for white noise.  To do that, I first set all the residuals = 0, then run the ADF test and finally will check for white noise.

genr resid = 0
freeze(mode=overwrite,a_tilde_4_adf) a_tilde_4.uroot(adf,const,trend,info=sic)
freeze(a_tilde_4_adf_correl) resid.correl
 
'Based on the Q-statistic, I conclude that the residuals are white noise.  Putting it all together, I conclude that the a_tilde_4 series is not level stationary.

'The next thing I do is test whether the differenced series is stationary using the ADF test.  I once again begin by graphing the (differenced) series.
 
genr a_tilde_4diff = d(a_tilde_4)
freeze(figure_a_tilde_4diff) a_tilde_4diff.line
figure_a_tilde_4diff.addtext(t) da_tilde_4 (Hong Kong):  1980-2008
figure_a_tilde_4diff.addtext(b) Year
figure_a_tilde_4diff.addtext(l) Da_tilde_4
figure_a_tilde_4diff.legend(off)

'From the graph, the series clearly does not have a time trend to it. So, I would test the series for unit with an intercept only.

'So we begin the whole process over again: 

genr a_tilde_4diff = d(a_tilde_4)
freeze(table_8_14_a_tilde_4diff1_adf) a_tilde_4diff.uroot(adf,const,info=sic)

'Note that the SIC automatic lag selection picks no lags, p =0.  The unit root test produces a t-value of -4.44 which is now smaller than our 5% criterion -2.98.  Thus, we may now reject the null of non-stationarity in first differenced series of a_tilde_4.  There is no reason to go further.  The last thing we do is to check ADF regression result for white noise.

genr resid = 0
freeze(mode=overwrite,a_tilde_4diff1_adf) a_tilde_4diff.uroot(adf,const,info=sic)
freeze(a_tilde_4diff1_adf_correl) resid.correl

''Based on the Q-statistic, I conclude that the residuals are white noise.  Putting it all together, I conclude that the a_tilde_4 series is I(1).

'************************************************************
'DF-GLS Unit Root Test for Hong Kong's Productivity
'************************************************************
 
freeze(table_8_14_a_tilde_4_dfgls) a_tilde_4.uroot(dfgls,trend,info=sic)

'Note that the SIC automatic lag selection picks lags, p = 1.  The unit root test produces a t-value of -1.39 which is greater than our 5% criterion -3.19.  Thus, at this point, we may not reject the null of a unit root.
 
'Now let's see if the series is difference stationary or not

genr a_tilde_4diff = d(a_tilde_4)
freeze(table_8_14_a_tilde_41diff1_dfgls) a_tilde_4diff.uroot(dfgls,const,info=sic)

'Note that the SIC automatic lag selection picks no lags, p = 1.  The unit root test produces a t-value of -4.18 which is smaller than our 5% criterion -1.95. Thus, we may reject the null of non-stationarity in first differenced series of a_tilde_4.  

''Putting it all together, I conclude that the a_tilde_4 series is I(1), a finding compatible with my ADF test results.

'*********************************************************************************
'DF-GLS Unit Root Test for Hong Kong's rer_def_NT_4
'We now run our first dfgls test
'**********************************************************************************
 
freeze(table_8_14_3_rer_def_NT_4_dfgls) rer_def_NT_4.uroot(dfgls,trend,info=sic)

'Note that the SIC automatic lag selection picks lags, p = 1.  The unit root test produces a t-value of -1.55 which is greater than our 5% criterion -3.19.  Thus, at this point, we may not reject the null of a unit root.

'Now let's see if the series is difference stationary or not

genr rer_def_NT_4diff = d(rer_def_NT_4)
freeze(table_8_14_rer_def_NT_4diff1_dfgls) rer_def_NT_4diff.uroot(dfgls,const,info=sic)

'Note that the SIC automatic lag selection picks no lags, p = 0.  The unit root test produces a t-value of - 2.27 which is smaller than our 5% criterion -1.95.  Thus, we may now reject the null of nonstationarity in first differenced series of rer_def_NT_4.  
 
''Putting it all together, I conclude that the rer_def_NT_4 series is I(1), a finding incompatable with my ADF test results.

'***************************************************************
'Graph for Hong Kong's  rer_def_T_4
'***************************************************************
                                        
genr rer_def_T_4 = rer_def_T_4
freeze(figure_rer_def_T_4) rer_def_T_4.line
figure_rer_def_T_4.addtext(t) rer_def_T_4 (Hong Kong):  1980-2013
figure_rer_def_T_4.addtext(b) Year
figure_rer_def_T_4.addtext(l) rer_def_T_4
figure_rer_def_T_4.legend(off)
                                                 
'We see from the FIGURE that rer_def_T_4 has a time trend to it.  So we would include both an intercept and a time trend in our unit root regression equtions. 

'*********************************************************************************
'ADF Unit Root Test for Hong Kong's rer_def_T_4
'We now run our first ADF test
'**********************************************************************************
 
freeze(table_8_14_1_rer_def_T_4_adf) rer_def_T_4.uroot(adf,trend,info=sic)

'Note that the SIC automatic lag selection picks lags, p = 4.  The unit root test produces a t-value of -1.80 which is greater than our 5% criterion -3.61.  Thus, at this point, we cannot reject the null of a unit root.

'Now, let's check for white noise.  To do that, I first set all the residuals = 0, then run the adf test and finally will check for white noise.

genr resid = 0
freeze(mode=overwrite,rer_def_T_4_adf) rer_def_T_4.uroot(adf,const,trend,info=sic)
freeze(rer_def_T_4_adf_correl) resid.correl
 
'Based on the Q-statistic, I conclude that the residuals are white noise.  Putting it all together, I conclude that the rer_def_T_4 series is not level stationary.

'The next thing I do is test whether the differenced series is stationary using the ADF test.  I once again begin by graphing the (differenced) series.
 
genr rer_def_T_4diff = d(rer_def_T_4)
freeze(figure_rer_def_T_4diff) rer_def_T_4diff.line
figure_rer_def_T_4diff.addtext(t) Drer_def_T_4 (Hong Kong):  1980-2013
figure_rer_def_T_4diff.addtext(b) Year
figure_rer_def_T_4diff.addtext(l) Drer_def_T_4
figure_rer_def_T_4diff.legend(off)

'The graph is not particularly illuminating.  Depending on how you look at it, it could have a time trend to it.  However, since the previous ADF test concluded that the equation for rer_def_T_4 do have a time trend, we run the ADF test with both a constant as well as a time trend.

'So we begin the whole process over again: 

genr rer_def_T_4diff = d(rer_def_T_4)
freeze(table_8_14_2_rer_def_T_4diff1_adf) rer_def_T_4diff.uroot(adf,const,info=sic)

'Note that the SIC automatic lag selection picks no lags, p =0.  The unit root test produces a t-value of -3.43 which is smaller our 5% criterion -2.98.  Thus, we may now reject the null of nonstationarity in first differenced series of rer_def_T_4.  There is no reason to go further.  The last thing we do is check for white noise.

genr resid = 0
freeze(mode=overwrite,rer_def_T_4diff1_adf) rer_def_T_4diff.uroot(adf,const,trend,info=sic)
freeze(rer_def_T_4diff1_adf_correl) resid.correl

''Based on the Q-statistic, I conclude that the residuals are white noise.  Putting it all together, I conclude that the rer_def_T_4 series is I(1).

'*********************************************************************************
'DF-GLS Unit Root Test for Hong Kong's rer_def_T_4
'We now run our first dfgls test
'**********************************************************************************
 
freeze(table_8_14_3_rer_def_T_4_dfgls) rer_def_T_4.uroot(dfgls,trend,info=sic)

'Note that the SIC automatic lag selection picks lags, p = 4.  The unit root test produces a t-value of -2.85 which is greater than our 5% criterion -3.19.  Thus, at this point, we may not reject the null of a unit root.

'Now let's see if the series is difference stationary or not

genr rer_def_T_4diff = d(rer_def_T_4)
freeze(table_8_14_rer_def_T_4diff1_dfgls) rer_def_T_4diff.uroot(dfgls,const,info=sic)

'Note that the SIC automatic lag selection picks no lags, p = 0.  The unit root test produces a t-value of -2.57 which is smaller than our 5% criterion -1.95.  Thus, we may now reject the null of nonstationarity in first differenced series of rer_def_T_4.  
 
''Putting it all together, I conclude that the rer_def_T_4 series is I(1), a finding compatable with my ADF test results.

'*********************************************
'Single Equation Cointegration Methods
'*********************************************

'******************************************************************
''Graph the suspected cointegrated series together
'******************************************************************
'The first step is to print out a graph of the series.  This is very important!

group g1 rer_def_NT_4 rer_def_T_4 a_tilde_4
freeze(figure1) g1.line(x)
figure1.setelem(1) lcolor(black) symbol(1) lpat(1)
figure1.setelem(2) lcolor(black) symbol(4) lpat(1)
figure1.setelem(3) lcolor(black) symbol(7) lpat(1)
figure1.setelem(3) lcolor(black)
figure1.options linepat
figure1.addtext(t) rer_def_NT_4, lnpT & a_tilde_4 (Hong Kong & U.S): 1980-2013
figure1.addtext(b) Year
figure1.addtext(l) rer_def_NT_4
figure1.addtext(l) lnpT
figure1.addtext(r) a_tilde_4

''*******************************************************
''S1.A.Engle-Granger Approach to Cointegration
'*******************************************************

genr resid = 0
equation eg.ls rer_def_NT_4 c rer_def_T_4 a_tilde_4
genr EC1 = resid

'First we test if the residuals of above regression are level stationary or not. If yes, next we'll proceed towards estimation of error correction model.

'***************************************************************
'Graph for Hong Kong's  EC
'***************************************************************                                               
genr EC1 = EC1
freeze(figure_EC1) EC1.line
figure_EC1.addtext(t) EC1 (Hong Kong):  1980-2013
figure_EC1.addtext(b) Year
figure_EC1.addtext(l) EC1
figure_EC1.legend(off)
                                                 
'We see from the FIGURE that EC has time trend to it.  So we would include both an intercept and trend in our unit root regression equtions. 

'*********************************************************************************
'EG Test for Cointegration
'**********************************************************************************
 
freeze(table_8_14_EGC) g1.coint(method=eg)

'The null hypothesis will not be rejected as suggested by sample statistics.

''******************************************
''S1.B.Error Correction Model (ECM)
'*******************************************
''*******************************************************
'Selecting the number of lags in the VAR  *
'*******************************************************
'NOTE: We do this because we need to have the "right" number of lags when it comes time to estimate our VEC model and test for cointegration.

var var1.ls 1 6   g1
freeze(var1_lagtest1) var1.laglen(6)
freeze(var1_lagtest2) var1.testlags

'The laglength test above indicates that the regressions should have 6 lags. But we can't afford to have this much number of lag. So, let's start with 1 lag and will raise the number of lags (up to a moderate extent) till obtaining white residuals.

var var2.ls 1 2  g1
freeze(var2_artest1) var2.correl
freeze(var2_artest2) var2.qstats(12)
freeze(var2_artest3) var2.arlm(12)

'The residuals are not white noise. But I can't go beyond this number of lags.

'We now try different lags of d(rer_def_T_4) and d(a_tilde_4), comparing SIC values across specifications.

genr resid = 0
equation eg.ls rer_def_NT_4 c rer_def_T_4 a_tilde_4
genr ec1 = resid

var table_8_14_eg2a.ls 0 0 d(rer_def_NT_4)   @  c ec1(-1) d(rer_def_NT_4(-1)) d(rer_def_NT_4(-2)) 

var table_8_14_eg2b.ls 0 0 d(rer_def_NT_4)   @  c ec1(-1) d(rer_def_NT_4(-1)) d(rer_def_NT_4(-2)) d(rer_def_T_4(-1)) d(a_tilde_4(-1))

var table_8_14_eg2c.ls 0 0 d(rer_def_NT_4)   @  c ec1(-1) d(rer_def_NT_4(-1)) d(rer_def_NT_4(-2)) d(rer_def_T_4(-1)) d(rer_def_T_4(-2)) d(a_tilde_4(-1)) d(a_tilde_4(-2))

'The evidence suggests that Model A is best.  Now we test that model for serial correlation.

var table_8_14_eg2b.ls 0 0 d(rer_def_NT_4)   @   c ec1(-1) d(rer_def_NT_4(-1)) d(rer_def_NT_4(-2)) d(rer_def_T_4(-1)) d(a_tilde_4(-1))
freeze(table_8_14_eg2b1_artest1) table_8_14_eg2b.correl
freeze(table_8_14_eg2b2_artest2) table_8_14_eg2b.qstats(12)
freeze(table_8_14_eg2b3_artest3) table_8_14_eg2b.arlm(12)

'The residuals are absolutely white noise.

''*************************
''Estimating EC Model  
'**************************

'We'll now take the above specified model and turn it into an ECM. We shall run NW-HAC least squares model for establishing error correction mechanism.

'We now estimate the corresponding ECM:

equation table_8_14_ecm.ls(n) d(rer_def_NT_4) c ec1(-1) d(rer_def_NT_4(-1)) d(rer_def_NT_4(-2)) d(rer_def_T_4(-1)) d(a_tilde_4(-1))

'Note that the SR effect is insignificant as the EC coefficient (-0.01) is statistically insignificant.

''******************************************
'Multivariate Cointegration Approach
'******************************************

''*************************************************************
''Check if the VAR(2) model is dynamically stable
'*************************************************************
freeze(table_8_14_var2_varstable) var2.arroots(graph)

'The model is dynamically stable.

''**********************************************************************
''M1.A & M1.B: Identifying the number of cointegrating vectors
'***********************************************************************
'Having identified the appropriate number of lags to put in, I now go on to test for the appropriate number of cointegrating equations.

freeze(table_8_14_var2_coint) var2.coint(s,2)

'This command estimates all possible combinations of constants and trends in the level data series and the cointegrating equations. All the results indicate 1 cointegrating vectors.
'
'GENERAL NOTE:, in practice, cases 1 and 5 are rarely used. One should use case 1 only if one knows that all series have zero mean. Case 5 may provide a good fit in-sample but will produce implausible forecasts out-of-sample. As a rough guide, use case 2 if none of the series appear to have a trend. For trending series, use case 3 if you believe all trends are stochastic; if you believe some of the series are trend stationary, use case 4.

'Note that the 5 cases are identified under "Johansen cointegration test" in Eviews. They run from most restrictive (no constants in either the level series or CEs) to most general (trend terms in both the level series and CEs).

''******************************************************************
''M2.A, M2.B & M3: Vector Error Correction Model (VECM)
'*******************************************************************

' For estimating the LR relationship, corresponding VEC command is:

var table_8_14_vec_c.ec(c,1) 1 1 rer_def_NT_4 rer_def_T_4 a_tilde_4

var table_8_14_vec_d.ec(d,1) 1 1 rer_def_NT_4 rer_def_T_4 a_tilde_4

'CONCLUSION:  I conclude that  there is mixed evidence in support of cointegration between rer_def_NT_4 and a_tilde_4 in Hong Kong's data.


